package com.chb.test.waitAndnotify_08;

public class Cook extends Thread{
    @Override
    public void run() {
        while (true) {
            synchronized (Desk.look) {
                if(Desk.count == 0) {
                    break;
                } else {
                    // 判断桌上是否有食物，没有则制作食物，有则等待
                    if(Desk.foodFlag == 0) {
                        System.out.println(getName() + "面条已制作完成，当前桌上已有面条，还剩余" + (Desk.count - 1) + "碗");
                        Desk.foodFlag = 1;
                        Desk.look.notifyAll();
                    } else {
                        // 桌上有面条，则唤醒消费者吃面条
                        try {
                            Desk.look.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
